/*
 * @Author: 颜礼田 2564217790@qq.com
 * @Date: 2024-09-10 10:57:39
 * @LastEditors: 颜礼田 2564217790@qq.com
 * @LastEditTime: 2024-09-10 11:01:10
 * @FilePath: /webServer/src/validator/department/department.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { ApiProperty } from '@midwayjs/swagger';
import { getSchema, Rule, RuleType } from '@midwayjs/validate';
import { alternatives, StrIdNullValidator } from '..';
import { DepartmentSchema } from '../../schema';

export class SaveDepartmentValidator implements DepartmentSchema {
  @ApiProperty({
    type: StrIdNullValidator,
    title: '父级部门',
    example: 'null',
    description: '父级部门',
    required: false,
  })
  @Rule(getSchema(StrIdNullValidator).allow())
  parent?: DepartmentSchema;

  @ApiProperty({
    type: 'string',
    title: '部门名称',
    example: 'null',
    description: '部门名称',
    required: true,
  })
  @Rule(RuleType.string().required())
  deptName: string;

  @ApiProperty({
    type: 'string',
    title: '部门编码',
    example: 'null',
    description: '部门编码',
    required: true,
  })
  @Rule(RuleType.string().required())
  deptCode: string;
}

export class EditDepartmentValidator implements Partial<DepartmentSchema> {
  @ApiProperty({
    type: StrIdNullValidator,
    title: '父级部门',
    example: 'null',
    description: '父级部门',
    required: false,
  })
  @Rule(getSchema(StrIdNullValidator).allow())
  parent?: DepartmentSchema;

  @ApiProperty({
    type: 'string',
    title: '部门名称',
    example: 'null',
    description: '部门名称',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  deptName?: string;

  @ApiProperty({
    type: 'string',
    title: '部门编码',
    example: 'null',
    description: '部门编码',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  deptCode?: string;
}
